package com.yanqu.road.server.cmd.activity.xingyoushanshui.cross;

import com.yanqu.road.entity.activity.youxing.config.XingYouConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shanshui.XingYouShanShuiModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.shanshui.XingYouShanShuiMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.config.Config;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_BATTLE_DATA_UPLOAD_NOTIFY,desc = "玩家战斗数据上报(通知)")
public class ShanShauiNotifyUploadFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        XingYouShanShuiProto.CrossShanShuiNotifyUpload upload = XingYouShanShuiProto.CrossShanShuiNotifyUpload.parseFrom(yanQuMessage.getBytes());
        XingYouConfig config = XingYouShanShuiMgr.getConfig();
        if(config == null){
            return;
        }
        if(!ActivityMgr.activityInShowTime(config.getActivityInfo())){
            return;
        }
        for (Long uid : upload.getUserIdList()) {
            GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(uid);
            if(onlinePlayer == null){
                if(Config.isDebug()){
                    onlinePlayer = GamePlayerMgr.getPlayer(uid);
                }else {
                    continue;
                }
            }
            XingYouShanShuiProto.CrossShanShuiBattleDataUpload.Builder builder = XingYouShanShuiProto.CrossShanShuiBattleDataUpload.newBuilder();
            builder.setActivityId(config.getActivityInfo().getActivityId());
            onlinePlayer.getModule(XingYouShanShuiModule.class).uploadBeautyAbility(false);
        }
    }
}
